<template>
	<view class="container">
		<view class="user-section">
			<image class="bg" src="/static/ssmall/bg.png" mode="bottom"></image>
			<view class="user-info-box">
				<image class="portrait" :src="userInfo.userPhoto || '/static/mixmall/missing-face.png'"
					@click.stop="navTo('/pages/login/login')"></image>
				<text class="username">{{userInfo.userName || '游客'}}</text>
			</view>
		</view>

		<view class="user-info-section">
			<view class="money">
				<text class="digit">190</text>
				<text class="title">余额</text>
			</view>
			<view class="coupon">
				<text class="digit">3</text>
				<text class="title">优惠券</text>
			</view>
			<view class="points">
				<text class="digit">300</text>
				<text class="title">积分</text>
			</view>
		</view>

		<view class="user-order-section">
			<view class="order-item" @click="navTo('/pages/order/order?state=0')" hover-class="common-hover"
				:hover-stay-time="50">
				<text class="yticon icon-shouye"></text>
				<text>全部订单</text>
			</view>
			<view class="order-item" @click="navTo('/pages/order/order?state=1')" hover-class="common-hover"
				:hover-stay-time="50">
				<text class="yticon icon-daifukuan"></text>
				<text>待付款</text>
			</view>
			<view class="order-item" @click="navTo('/pages/order/order?state=2')" hover-class="common-hover"
				:hover-stay-time="50">
				<text class="yticon icon-yishouhuo"></text>
				<text>待发货</text>
			</view>
			<view class="order-item" @click="navTo('/pages/order/order?state=3')" hover-class="common-hover"
				:hover-stay-time="50">
				<text class="yticon icon-yishouhuo"></text>
				<text>待收货</text>
			</view>
			<view class="order-item" @click="navTo('/pages/order/order?state=4')" hover-class="common-hover"
				:hover-stay-time="50">
				<text class="yticon icon-pingjia"></text>
				<text>待评价</text>
			</view>
		</view>

		<view class="user-function-section">
			<list-cell icon="icon-iconfontweixin" iconColor="#e07472" title="我的钱包" tips="您的会员还有3天过期"></list-cell>
			<list-cell icon="icon-dizhi" iconColor="#5fcda2" title="地址管理" @eventClick="navTo('/pages/address/address')">
			</list-cell>
			<list-cell icon="icon-share" iconColor="#9789f7" title="分享" tips="邀请好友赢10万大礼" @eventClick="share"></list-cell>
			<list-cell icon="icon-pinglun-copy" iconColor="#ee883b" title="晒单" tips="晒单抢红包"></list-cell>
			<list-cell icon="icon-shoucang_xuanzhongzhuangtai" iconColor="#54b4ef" title="我的收藏"></list-cell>
			<list-cell icon="icon-shezhi1" iconColor="#e07472" title="设置" border=""
				@eventClick="navTo('/pages/setting/setting')"></list-cell>
		</view>
		
		<share ref="share" :contentHeight="580" :shareList="shareList"></share>
	</view>
</template>

<script>
	import listCell from '@/components/mix-list-cell';
	import share from '@/components/share';
	
	import {
		mapState
	} from 'vuex'

	export default {
		components: {
			listCell,share
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		data() {
			return {
				shareList: []
			}
		},
		async onLoad() {
			this.shareList = await this.$api.json('shareList')
		},
		methods: {
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (!this.hasLogin) {
					url = '/pages/login/login';
				} else {
					if(url.indexOf('login') > 0) {
						return;
					} 
				}

				uni.navigateTo({
					url
				})
			},
			//分享
			share() {
				this.$refs.share.toggleMask();
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #F7F7F7;
	}

	%section {
		display: flex;
		justify-content: space-between;
		background-color: white;
		padding: 40rpx 30rpx;
		border-radius: 10rpx;
		margin: 20rpx 20rpx 0;
	}

	.user-section {
		// position: relative;
		padding: 50rpx 30rpx 0;

		.bg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 250rpx;
		}

		.user-info-box {
			display: flex;
			align-items: center;
			position: relative;
			z-index: 2;

			.portrait {
				width: 130rpx;
				height: 130rpx;
				// border: 5rpx solid #fff;
				border-radius: 50%;
			}

			.username {
				margin-left: 20rpx;
				color: #fff;
			}
		}
	}

	.user-info-section {
		display: flex;
		justify-content: space-between;
		background-color: white;
		padding: 40rpx 100rpx;
		border-radius: 10rpx;
		margin: 100rpx 20rpx 0;

		.money,
		.coupon,
		.points {
			display: flex;
			flex-direction: column;
			justify-content: center;
		}

		.digit {
			font-size: $uni-font-size-base;
			font-weight: bold;
			color: #333;
			text-align: center;
		}

		.title {
			font-size: $uni-font-size-base;
			color: $uni-text-color-grey;
		}
	}

	.user-order-section {
		display: flex;
		justify-content: space-between;
		background-color: white;
		padding: 40rpx 30rpx;
		border-radius: 10rpx;
		margin: 20rpx 20rpx 0;

		.order-item {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			border-radius: 10rpx;
			font-size: $uni-font-size-sm;
			color: $font-color-dark;
		}

		.yticon {
			font-size: 50rpx;
			margin-bottom: 18rpx;
			color: #fa436a;
		}

		.icon-shouhoutuikuan {
			font-size: 44rpx;
		}

	}

	.user-function-section {
		background-color: white;
		border-radius: 10rpx;
		margin: 20rpx 20rpx;
	}
</style>
